/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package contextManagement;

import java.util.Dictionary;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.upnp.UPnPAction;
import org.osgi.service.upnp.UPnPDevice;

/**
 *
 * @author huangqing
 */
public class TemperatureProvider implements ContextProvider{

       public String getValue() {
        String rep = "";
        BundleContext bc = userInterface.GraphicalUserInterface.getBundleContext();
        try{
            ServiceReference [] sr=bc.getServiceReferences(UPnPDevice.class.getName(), "("+UPnPDevice.TYPE+"=urn:schemas-upnp-org:device:Sensor:1)");
            UPnPDevice tempSensor=(UPnPDevice)bc.getService(sr[0]);
            UPnPAction getTemp=(tempSensor.getServices()[0]).getActions()[0];
            Dictionary result=getTemp.invoke(null);
           System.out.println("getTemp ==>"+getTemp.getName()+"::"+result);
              //StringTokenizer s=new StringTokenizer(result.toString());
             //rep=s.nextToken(":").toString();
               rep=result.get("ResultTemperature").toString();
         }catch(Exception e){
                 e.printStackTrace();
             }


        return rep;
    }

    public void setValue(String newValue) {
        throw new UnsupportedOperationException("Not supported yet.");
    }


}
